package org.nf.trading.service.app.product.impl;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.dao.CommentMapper;
import org.nf.trading.entity.Comment;
import org.nf.trading.exception.app.product.ProductDataException;
import org.nf.trading.service.app.product.CommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class CommentServiceImpl implements CommentService {
    private final CommentMapper commentMapper;

    @Override
    public List<Comment> getCommentsByProductId(Integer productId) {
//        BeanUtils.copyProperties();
        if (productId == null){
            log.error("异常信息：id为空");
            throw new ProductDataException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "id为空");
        }
        return commentMapper.getCommentsByProductId(productId);
    }
}
